-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP fix(gnovm): correct map key persistence #3127
base: master
Are you sure you want to change the base?
WIP fix(gnovm): correct map key persistence #3127
Conversation
another bug identified: // PKGPATH: gno.land/r/ptr_map
package ptr_map
import "fmt"
type MyStruct struct {
Name string
}
var (
m = map[[1]*MyStruct]string{}
i1 = &MyStruct{Name: "alice"}
key1 = [1]*MyStruct{i1}
)
func init() {
m[key1] = "first key"
}
func main() {
fmt.Println("Value for key1:", m[key1])
}
// Error:
// interface conversion: gnolang.Value is gnolang.RefValue, not *gnolang.ArrayValue this if fixed. |
also this, is it counterintuitive? // PKGPATH: gno.land/r/ptr_map
package ptr_map
type MyStruct struct {
Name string
}
var (
m = map[[1]*MyStruct]string{}
i1 = &MyStruct{Name: "alice"}
)
func main() {
// Create an array of pointers to MyStruct
key1 := [1]*MyStruct{i1}
m[key1] = "first key"
}
// Error:
// unexpected unreal object this is fixed but should consider the side effects on storage. XXX, the right way to fix it should me make map key object owned by map. |
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
This one should be fixed in another scope. // update: |
gnovm/tests/files/ptrmap5.gno
Outdated
key1 := [1]*MyStruct{i1} | ||
m[key1] = "first key" | ||
println(m[key1]) | ||
m[key1] = "second key" | ||
println(m[key1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current solution, assigning i1.Age = 3
creates a new key, leaving the old one dangling, which is not the expected behavior.
🛠 PR Checks Summary🔴 The pull request head branch must be up-to-date with its base (more info) Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
closes: #2060 and some other issues, by:
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description